/*
提交链接：https://leetcode.cn/problems/koko-eating-bananas/description/
875. 爱吃香蕉的珂珂
赖德檀 2024/9/17
*/

class Solution {
public:
bool test(vector<int>&arr,long long sum,int h)
{
    long long num=0;
    for(int i=0;i<arr.size();i++)
    {
        num+=(arr[i] + sum - 1) / sum;
    }
    return num<=h;
}
    int minEatingSpeed(vector<int>& piles, int h) {
        long long l=1,r= ranges::max(piles);
        while(l<r)
        {
            long long mid=(l+r)/2;          
            if(test(piles,mid,h))
            {
                r=mid;
            }
            else
            l=mid+1;
        }
        return l;
    }
};